<?php
class Dumper
{
    /**
     * Background CSS color, for example: "#000000" or "black"
     * 
     * @var string
     */
    public static $backgroundColor = 'white';
    
    /**
     * Braces CSS color, for example: "#000000" or "black"
     * 
     * @var string
     */
    public static $bracesColor = 'red';
    
    /**
     * Data type CSS color, for example: "#000000" or "black"
     * 
     * @var string
     */
    public static $typeColor = 'black';
    
    /**
     * Numeric value CSS color, for example: "#000000" or "black"
     * 
     * @var string
     */
    public static $numericValueColor = 'green';
    
    /**
     * put your comment there...
     * 
     * @var string
     */
    public static $stringsValueColor = 'blue';
    
    /**
     * String value CSS color, for example: "#000000" or "black"
     * 
     * @var string
     */
    public static $indexColor = '#FF8000';    
    
    /**
     * Sets custom color theme in one static method call.
     * 
     * @param string $backgroundColor Background CSS color, for example: "#000000" or "black"
     * @param string $indexColor Index CSS color, for example: "#000000" or "black"
     * @param string $bracesColor Braces CSS color, for example: "#000000" or "black"
     * @param string $typeColor Data type CSS color, for example: "#000000" or "black"
     * @param string $numericValueColor Numeric value CSS color, for example: "#000000" or "black"
     * @param string $stringsValueColor String value CSS color, for example: "#000000" or "black"
     * @return void
     */
    public static function setColors($backgroundColor, $indexColor, $bracesColor, $typeColor, $numericValueColor, $stringsValueColor) {
        self::$indexColor = $indexColor;
        self::$backgroundColor = $backgroundColor;
        self::$bracesColor = $bracesColor;
        self::$typeColor = $typeColor;
        self::$numericValueColor = $numericValueColor;
        self::$stringsValueColor = $stringsValueColor;
    }
    
    /**
     * Displays structured information about one or more expressions that includes its type and value. 
     * 
     * @param mixed $str Structure to display.
     * @return void
     */
    public static function dump($str) {
        echo '<pre style="color: '.self::$bracesColor.'; background-color: '.self::$backgroundColor.';" >';
        $header = "\"<span style=\\\"color: ".self::$indexColor."\\\">\$matches[1]</span><span style=\\\"color: ".self::$bracesColor."\\\">\$matches[2]</span><span style=\\\"color: ".self::$typeColor."\\\">\$matches[3]</span>\"";
        $function = create_function('$matches', '
            $count = count($matches);
            if($count == 7 && $matches[4] === $matches[5] && $matches[6]) {
                $ret = '.$header.'."<span style=\"color: '.self::$numericValueColor.'\">$matches[5]</span>";
            } else if($count == 7) {
                $ret = '.$header.'."<span style=\"color: '.self::$numericValueColor.'\">$matches[5]</span><span style=\"color: '.self::$stringsValueColor.'\">$matches[6]</span>";
            } else if($count == 4){
                $ret = '.$header.';
            } else if($count == 10) {
                $ret = '.$header.'."<span style=\"color: '.self::$numericValueColor.'\">$matches[6]</span><span style=\"color: '.self::$typeColor.'\">$matches[8]</span><span style=\"color: '.self::$numericValueColor.'\">$matches[9]</span>";
            } else if($count == 11) {
                // strings
                $ret = '.$header.'."<span style=\"color: '.self::$numericValueColor.'\">$matches[5]</span><span style=\"color: '.self::$stringsValueColor.'\">$matches[10]</span>";
            } else {
                $ret = $matches[0];
            }
            return $ret;
            
        ');
        ob_start();
        var_dump($str);
        $str = '["commentid"]=>'."\n ".ob_get_clean();
        $str = preg_replace_callback('~(\[[^\]]+\]|[\d]+)(=>\n\s+)([a-zA-Z_\d]+)(((\([^)]+\))((#[\d]+)(\s\([\d]+\)))?)(\s"[^"]*")?)?~', $function, $str);

        $str = ltrim(substr($str, strpos($str, "\n ")));
        echo $str;
        echo "</pre>";
    } 
    
   
}

/**
 * Displays structured information about one or more expressions that includes its type and value. 
 * 
 * @param mixed $str Structure to display.
 * @return void

function dump($args) {
    $args = func_get_args();
    foreach($args as $arg) {
        Dumper::dump($arg);
    }
}      
  */ 
  
  
//$arr[]='sdfdsf';
//$arr[]='ddd333';
//dump($arr);
